import RPi.GPIO as GPIO
import time

# 设置GPIO模式
GPIO.setmode(GPIO.BCM)

# 设置GPIO引脚14为输入
GPIO.setup(14, GPIO.IN)

# 初始化按键状态为未按下
key_pressed = False

try:
    while True:
        # 检查按键是否按下
        if GPIO.input(14):
            key_pressed = True
            print("Key pressed!")
        else:
            if key_pressed:
                print("Key released!")
                key_pressed = False

        # 每秒检查一次按键状态
        time.sleep(1)

except KeyboardInterrupt:
    # 清理GPIO资源
    GPIO.cleanup()

